package net.zcy.zalllonely.common.exception.handle;

import net.zcy.zalllonely.common.exception.ZallException;
import net.zcy.zalllonely.common.exception.util.Result;
import net.zcy.zalllonely.common.exception.util.ResultUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

@RestControllerAdvice
public class ExceptionHandle {

    private static Logger LOG = LoggerFactory.getLogger(ExceptionHandle.class);

    @ExceptionHandler(value = Exception.class)
    public Result handle(Exception e){

        if(e instanceof ZallException){
            ZallException zallException = (ZallException) e;
            return ResultUtil.error(zallException.getCode(),zallException.getMessage());
        }else{
            LOG.error("【系统异常】 ：" ,e);
            return ResultUtil.sysError();
        }

    }
}
